package com.ww.springboot.boot.javabase.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-03-04 09:13
 */
public class StreamDemo1 {


    public static void main(String[] args) {
        List<Integer> list = IntStream.range(0, 10).boxed().collect(Collectors.toList());
        System.out.println(list);
        //flatmap 将每个元素转换为stream
        List<Integer> list2 = list.stream().flatMap(i -> IntStream.range(0, i).boxed()).collect(Collectors.toList());
        System.out.println(list2);
        List<Integer> list4 = list.stream().flatMapToInt(i -> IntStream.range(0, i)).boxed().collect(Collectors.toList());
        System.out.println(list4);
        int sum = list.stream().flatMapToInt(i -> IntStream.range(0, i)).sum();
        System.out.println(sum);
        int[] ints = list.stream().flatMapToInt(i -> IntStream.range(0, i)).toArray();
        System.out.println(ints.length);
        List<String> list3 = list.stream().map(i -> i.toString()).collect(Collectors.toList());
        System.out.println(list3);


//        Map<Integer, List<Integer>> collect = list.stream().collect(Collectors.groupingBy(i -> i % 2));
//        System.out.println(collect);
        System.out.println(list.stream().collect(Collectors.groupingBy(i -> i % 2, Collectors.summingInt(i -> i))));
//        System.out.println(collect);

    }
}
